home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Frameworks / MADE 1.0.1 / Essential Errors.c < prev    next >
Encoding:
Text File  |  1997-06-04  |  2.8 KB  |  127 lines  |  [TEXT/CWIE]

  1. // MADE - Macintosh Application Development Essentials
  2. // ---------------------------------------------------
  3.  
  4. // (c) Gideon Greenspan, Sig Software - June 1997 - http://www.kagi.com/gdg/
  5.  
  6. // These files can only be used for experimental standalone purposes. To obtain
  7. // fully commented code, and licenses for standalone, shareware, internal and
  8. // commercial usage, run the enclosed Register application.
  9.  
  10. // Essential Errors.c
  11. //
  12. // Error checking, handling, reporting and assertion support.
  13. //
  14. // Version 1.0.0 - 10th November 1996
  15.  
  16. #include "Essential Headers.h"
  17. #include "Essential Prototypes.h"
  18.  
  19. #if Project_Under_Development
  20.  
  21.     void    HandleAssertFailure(char* file, char* date, int line)
  22.     {
  23.         Str255            fileString, dateString, lineString, memoryString;
  24.         unsigned char    *stringPtr;
  25.         
  26.         stringPtr=fileString+1;
  27.         while (*stringPtr++=*file++);
  28.         *fileString=stringPtr-fileString-2;
  29.         
  30.         stringPtr=dateString+1;
  31.         while (*stringPtr++=*date++);
  32.         *dateString=stringPtr-dateString-2;
  33.         
  34.         NumToString(line, lineString);
  35.         NumToString(MaxBlock(), memoryString);
  36.         
  37.         ParamText(fileString, dateString, lineString, memoryString);
  38.  
  39.         switch (Alert(32767, 0)) {
  40.             case 1:
  41.                 Debugger();
  42.                 break;
  43.             case 2:
  44.                 ExitToShell();
  45.                 break;
  46.             case 3:
  47.                 ExecutionBody();
  48.                 break;
  49.             case 4:
  50.                 break;
  51.         }
  52.     }
  53.  
  54. #endif
  55.  
  56. void    TestError(Error error)
  57. {
  58.     Str255            IDString, messageString;
  59.     short            numString, totalStrings, compareError;
  60.     Handle            errorsResource;
  61.     char            *errorStrings;
  62.     unsigned char    charsToCopy, *messagePointer;
  63.     
  64.     if (error) {
  65.         NumToString(error, IDString);
  66.         
  67.         errorsResource=GetResource('ErrS', 128);
  68.         if (ResError() || errorsResource==0)
  69.             SysBeep(1); // If that failed, then we're really in trouble so just beep!
  70.         
  71.         else {
  72.             errorStrings=*errorsResource;
  73.             totalStrings=*(short*)errorStrings;
  74.             errorStrings+=sizeof(short);
  75.             
  76.             for (numString=0; numString<totalStrings; numString++) {
  77.                 compareError=*(short*)errorStrings;
  78.                 errorStrings+=sizeof(short);
  79.  
  80.                 if (compareError==error) {
  81.  
  82.                     charsToCopy=*(unsigned char*)errorStrings+1;
  83.                     messagePointer=messageString;
  84.  
  85.                     while (charsToCopy--)
  86.                         *messagePointer++=*errorStrings++;
  87.                     goto stringFound;
  88.  
  89.                 } else
  90.                     errorStrings+=*(unsigned char*)errorStrings+1;
  91.             }
  92.  
  93.             *messageString=0;
  94.  
  95.             stringFound:
  96.             ParamText(IDString, messageString, 0, 0);
  97.             Alert(128, 0);
  98.         }
  99.     }
  100. }
  101.  
  102. Error    TestResError(void* resource)
  103. {
  104.     Error    error;
  105.     
  106.     error=ResError();
  107.     if (!error)
  108.         if (resource==0L)
  109.             error=resNotFound; // It is unclear which error it should be, so this will do
  110.     TestError(error);
  111.     
  112.     return error;
  113. }
  114.  
  115. Error    TestMemError(void* pointer)
  116. {
  117.     Error    error;
  118.     
  119.     error=MemError();
  120.     if (!error)
  121.         if (pointer==0L)
  122.             error=memFullErr; // It is unclear which error it should be, so this will do
  123.     TestError(error);
  124.     
  125.     return error;
  126. }
  127.